package com.mmc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.mmc.entity.LoginUser;
import com.mmc.entity.User;
import com.mmc.exception.Assert;
import com.mmc.mapper.UserMapper;
import com.mmc.result.ResponseEnum;
import com.mmc.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mmc.utils.MD5;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-09-13
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Override
    public LoginUser login(User user) {
        User one = this.getOne(new LambdaQueryWrapper<User>().eq(User::getUsername, user.getUsername()));
        //判断是否有该用户
        Assert.notNull(one, ResponseEnum.LOGIN_MOBILE_ERROR);
        //判断密码是否正确
        String encrypt = MD5.encrypt(user.getPassword());
        Assert.equals(encrypt,one.getPassword(),ResponseEnum.LOGIN_PASSWORD_ERROR);
        LoginUser loginUser=new LoginUser();
        loginUser.setUser(user);
        loginUser.setUserId(user.getId());
        //权限列表

        return loginUser;
    }
}
